package love.yuanmeng.guetcoalsystem.service.impl;

/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:HuangHongTao
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/10/14 20:56
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import love.yuanmeng.guetcoalsystem.mapper.EnterpriseInfoMapper;
import love.yuanmeng.guetcoalsystem.mapper.LoginMapper;
import love.yuanmeng.guetcoalsystem.pojo.EnterpriseInfo;
import love.yuanmeng.guetcoalsystem.pojo.User;
import love.yuanmeng.guetcoalsystem.service.LoginService;
import love.yuanmeng.guetcoalsystem.util.DataGridView;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LoginServiceImpl implements LoginService {

    @Resource
    private LoginMapper loginMapper;
    @Resource
    private EnterpriseInfoMapper enterpriseInfoMapper;

    @Override
    public DataGridView login(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone",user.getPhone())
                .eq("userpaw",user.getUserpaw());
        User getUser = loginMapper.selectOne(wrapper);
        if (getUser!=null){
            EnterpriseInfo enterpriseInfo=enterpriseInfoMapper.selectById(getUser.getEnterpriseid());
            Map<String ,Object> map=new HashMap<>();
            map.put("userInfo",getUser);
            map.put("enterpriseInfo",enterpriseInfo);
            return  new DataGridView(200,map);
        }else
        return new DataGridView(-1,null);
    }
}
